package productmanagement;

import java.util.ArrayList;
import java.util.Collection;

public class ProductManagement {
    private Collection<Product> products;

    public ProductManagement() {
        this.products = new ArrayList<>();
    }


    public void addProduct(Product product){
        products.add(product);
        System.out.println(product + "商品添加成功!");
    }


    public void removeProduct(Product product){
        if (products.remove(product)) {
            System.out.println(product + "商品删除成功!");
        }else{
            System.out.println(product + "商品不存在,删除失败!");
        }
    }


    public Product FindProductByid(String id){
        for (Product product : products) {
            if(product.getId().equals(id)){
                return product;
            }
        }
        return null;
    }


    public void ShowAllProducts(){
        if (products.isEmpty()) {
            System.out.println("商品管理系统中没有商品");
        }else{
            System.out.println("商品管理系统中的商品:");
            for (Product product : products) {
                System.out.println(product);
            }
        }
    }
}
